﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ExhibitionDraw.Model;
using ExhibitionDraw.Service;

namespace ExhibitionDraw.Control
{
    public partial class StandChild : ChildWindow
    {
        Service.CommServiceClient client = null;
        public string strPoint{get;set;}

        public int PavID { get; set; }

        public int FloorID { get; set; }

        public StandChild()
        {
            client = Server.ServiceHelper.InitService();
            InitializeComponent();
            //this.Title = "";
            InitData(); 
        }

        private void InitData()
        {

            client.GetBoothClassListAsync();
            client.GetBoothClassListCompleted += new EventHandler<Service.GetBoothClassListCompletedEventArgs>(BothClass_Complete);
            client.GetColorListAsync();
            client.GetColorListCompleted += new EventHandler<Service.GetColorListCompletedEventArgs>(ColorList_Complete);
        }

        private void BothClass_Complete(object sender, Service.GetBoothClassListCompletedEventArgs e)
        {
            if (e.Result.Count() > 0)
            {
                ClassId.DisplayMemberPath = "ClassType";
                ClassId.ItemsSource = e.Result;
                ClassId.SelectedIndex = 0;

            }
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            
            Service.StandModel mdl = new Service.StandModel();
            mdl.StandNum = StandNum.Text;
            mdl.DisplayNum = DisplayNum.Text;
            var clsMdl = ClassId.SelectedValue as BoothClassModel;
            if (clsMdl != null)
            {
                mdl.ClassId = Convert.ToInt32(clsMdl.Id);
            }
            
            mdl.StandLen = Convert.ToInt32( StandLen.Text);
            mdl.StandWidth =Convert.ToInt32( StandWidth.Text);
            mdl.StandSize =Convert.ToInt32(  StandSize.Text);
            mdl.DisplayMsg = DisplayMsg.Text;
            Service.ColorTypeModel obj = ColorTpId.SelectedItem as Service.ColorTypeModel;
            mdl.ColorTpId = Convert.ToInt32(obj.Id);
            mdl.Points = strPoint;
            mdl.PavID = PavID;
            mdl.FloorID = FloorID;
            client.SaveStandAsync(mdl);
            client.SaveStandCompleted += new EventHandler<Service.SaveStandCompletedEventArgs>(SaveComplete);
            
          
        }

        private void SaveComplete(object sender, Service.SaveStandCompletedEventArgs e)
        {
           

            string strMsg = e.Result == 1 ? "恭喜你数据保存成功!" : "对不起数据保存失败，请联系管理员！";

            MessageWin win = new MessageWin();
            win.txtMsg.Text = strMsg;
            win.Show();

           
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();   
        }
        /// <summary>
        /// 配色方案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ColorList_Complete(object sender,Service.GetColorListCompletedEventArgs e) {

            if (e.Result.Count()>0)
            {
                ColorTpId.DisplayMemberPath = "ColorTypeName";
                ColorTpId.ItemsSource = e.Result;
                ColorTpId.SelectedIndex = 0;

            }
        }
    }
}

